package com.yin.unsafe;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArraySet;

public class SetTest {
    public static void main(String[] args) {


        // JUC 写法
        Set<String> set1 = new CopyOnWriteArraySet<>();

        Set<String> set = Collections.synchronizedSet(new HashSet<>());

        for (int i = 1; i <= 100; i++) {
            new Thread(() -> {
                set.add(UUID.randomUUID().toString().substring(0, 5));
                System.out.println(set);
            }, String.valueOf(i)).start();

        }
    }
}
